package org.common.util;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.net.InetAddress;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.util.Arrays;


/**
 * my System utils
 * user.dir	:	项目根路径
 * java.runtime.name	:	Java(TM) SE Runtime Environment
sun.boot.library.path	:	E:\soft\java8\jdk\jre\bin
java.vm.version	:	25.60-b23
java.vm.vendor	:	Oracle Corporation
java.vendor.url	:	http://java.oracle.com/
path.separator	:	;
java.vm.name	:	Java HotSpot(TM) 64-Bit Server VM
file.encoding.pkg	:	sun.io
user.country	:	CN
user.script	:	
sun.java.launcher	:	SUN_STANDARD
sun.os.patch.level	:	
java.vm.specification.name	:	Java Virtual Machine Specification
java.runtime.version	:	1.8.0_60-b27
java.awt.graphicsenv	:	sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs	:	E:\soft\java8\jdk\jre\lib\endorsed
os.arch	:	amd64
java.io.tmpdir	:	C:\Users\doris\AppData\Local\Temp\
line.separator	:	

java.vm.specification.vendor	:	Oracle Corporation
user.variant	:	
os.name	:	Windows 10
sun.jnu.encoding	:	GBK
java.library.path	:	E:\soft\java8\jdk\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;E:/soft/java8/jdk/bin/../jre/bin/server;E:/soft/java8/jdk/bin/../jre/bin;E:/soft/java8/jdk/bin/../jre/lib/amd64;C:\Program Files (x86)\Common Files\Intel\Shared Files\cpp\bin\Intel64;E:\soft\java8\jdk\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;F:\qing\eclipse;;.
java.specification.name	:	Java Platform API Specification
java.class.version	:	52.0
sun.management.compiler	:	HotSpot 64-Bit Tiered Compilers
os.version	:	10.0
user.home	:	C:\Users\doris
user.timezone	:	
java.awt.printerjob	:	sun.awt.windows.WPrinterJob
file.encoding	:	UTF-8
java.specification.version	:	1.8
java.class.path	:	E:\qing\eclipse\workspace\qc-parent\qc-freemarker\target\test-classes;E:\qing\eclipse\workspace\qc-parent\qc-freemarker\target\classes;E:\qing\eclipse\workspace\qc-parent\qc-util\target\classes;E:\soft\java8\maven\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar;E:\soft\java8\maven\xml-apis\xml-apis\1.0.b2\xml-apis-1.0.b2.jar;E:\soft\java8\maven\org\springframework\spring-aop\4.2.4.RELEASE\spring-aop-4.2.4.RELEASE.jar;E:\soft\java8\maven\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;E:\soft\java8\maven\org\springframework\spring-core\4.2.4.RELEASE\spring-core-4.2.4.RELEASE.jar;E:\soft\java8\maven\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;E:\soft\java8\maven\org\springframework\spring-aspects\4.2.4.RELEASE\spring-aspects-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\aspectj\aspectjweaver\1.8.7\aspectjweaver-1.8.7.jar;E:\soft\java8\maven\org\springframework\spring-beans\4.2.4.RELEASE\spring-beans-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-context\4.2.4.RELEASE\spring-context-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-context-support\4.2.4.RELEASE\spring-context-support-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-expression\4.2.4.RELEASE\spring-expression-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-instrument\4.2.4.RELEASE\spring-instrument-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-instrument-tomcat\4.2.4.RELEASE\spring-instrument-tomcat-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-jdbc\4.2.4.RELEASE\spring-jdbc-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-jms\4.2.4.RELEASE\spring-jms-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-messaging\4.2.4.RELEASE\spring-messaging-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-orm\4.2.4.RELEASE\spring-orm-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-oxm\4.2.4.RELEASE\spring-oxm-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-tx\4.2.4.RELEASE\spring-tx-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-web\4.2.4.RELEASE\spring-web-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\springframework\spring-webmvc\4.2.4.RELEASE\spring-webmvc-4.2.4.RELEASE.jar;E:\soft\java8\maven\org\apache\commons\commons-lang3\3.3\commons-lang3-3.3.jar;E:\soft\java8\maven\commons-io\commons-io\1.3.2\commons-io-1.3.2.jar;E:\soft\java8\maven\org\springframework\spring-test\4.2.4.RELEASE\spring-test-4.2.4.RELEASE.jar;E:\soft\java8\maven\net\sf\json-lib\json-lib\2.4\json-lib-2.4-jdk15.jar;E:\soft\java8\maven\commons-beanutils\commons-beanutils\1.8.0\commons-beanutils-1.8.0.jar;E:\soft\java8\maven\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar;E:\soft\java8\maven\commons-lang\commons-lang\2.5\commons-lang-2.5.jar;E:\soft\java8\maven\net\sf\ezmorph\ezmorph\1.0.6\ezmorph-1.0.6.jar;E:\soft\java8\maven\org\json\json\20150729\json-20150729.jar;E:\soft\java8\maven\mysql\mysql-connector-java\5.1.36\mysql-connector-java-5.1.36.jar;E:\soft\java8\maven\org\apache\tomcat\tomcat-dbcp\7.0.67\tomcat-dbcp-7.0.67.jar;E:\soft\java8\maven\org\apache\tomcat\tomcat-juli\7.0.67\tomcat-juli-7.0.67.jar;E:\soft\java8\maven\org\eclipse\persistence\javax.persistence\2.1.1\javax.persistence-2.1.1.jar;E:\soft\java8\maven\junit\junit\4.8.1\junit-4.8.1.jar;E:\soft\java8\maven\org\freemarker\freemarker\2.3.20\freemarker-2.3.20.jar;/F:/qing/eclipse/configuration/org.eclipse.osgi/382/0/.cp/;/F:/qing/eclipse/configuration/org.eclipse.osgi/381/0/.cp/
user.name	:	doris
java.vm.specification.version	:	1.8
sun.java.command	:	org.eclipse.jdt.internal.junit.runner.RemoteTestRunner -version 3 -port 55306 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -test org.qc.freemarker.project.ProjectTest:testPath
java.home	:	E:\soft\java8\jdk\jre
sun.arch.data.model	:	64
user.language	:	zh
java.specification.vendor	:	Oracle Corporation
awt.toolkit	:	sun.awt.windows.WToolkit
java.vm.info	:	mixed mode
java.version	:	1.8.0_60
java.ext.dirs	:	E:\soft\java8\jdk\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext
sun.boot.class.path	:	E:\soft\java8\jdk\jre\lib\resources.jar;E:\soft\java8\jdk\jre\lib\rt.jar;E:\soft\java8\jdk\jre\lib\sunrsasign.jar;E:\soft\java8\jdk\jre\lib\jsse.jar;E:\soft\java8\jdk\jre\lib\jce.jar;E:\soft\java8\jdk\jre\lib\charsets.jar;E:\soft\java8\jdk\jre\lib\jfr.jar;E:\soft\java8\jdk\jre\classes
java.vendor	:	Oracle Corporation
file.separator	:	\
java.vendor.url.bug	:	http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding	:	UnicodeLittle
sun.cpu.endian	:	little
sun.desktop	:	windows
sun.cpu.isalist	:	amd64
 * 
 * @author soul
 *
 */
public class SS {
	public static final File ROOTPATH;
	public static final File CLASSPATH;
	static{
		CLASSPATH=new File(getClassPath());
		ROOTPATH=CLASSPATH.getParentFile().getParentFile();
	}
	
	  /**
     * 获得JVM虚拟机对象
     * @return 
     */
    public static ClassLoader getClassLoader(){
	    	return Thread.currentThread().getContextClassLoader();
	}
    /**
     * 获取环境变量	
     */
    public static String getenv(String key){
    	return System.getenv(key);
    }
    /**
     * 获得JVM虚拟机对象
     * @return
     */
    public  ClassLoader getClassLoader0(){
	    	return this.getClass().getClassLoader();
       }
   /**
    * 
    * @return
    */
    public static String getClassPath(){
    	System.out.println(">>>>>>");
    	String pn="global.properties";
 		URL url = getClassLoader().getResource(pn);
 		
 		File f =null;
 		try {
			 f =new File(url.toURI());
		} catch (URISyntaxException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 		String classPathName = f.getPath();
 		int endingIndex = classPathName.length()-pn.length();
 		classPathName = classPathName.substring(0, endingIndex);
 		return classPathName;
 	}
    /**
     * 获取jar包路径
     * @return
     */
    public static String getJarPath(){
    	String jarPath=null;
		if(jarPath==null){
			URL url = SS.class.getProtectionDomain().getCodeSource().getLocation(); 
			File f=null;
			try {
				 f =new File(url.toURI());
			} catch (URISyntaxException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			jarPath=f.getAbsolutePath();
		}
		return jarPath;
		
	}

    public static boolean isWindowOs(){
    	String os = System.getProperty("os.name");  
		if(os.toLowerCase().startsWith("win")){  
			return true;
		}else{
			return false;
		}
    }

    public static InetAddress getInetAddress(){  
        try{  
            return InetAddress.getLocalHost();  
        }catch(UnknownHostException e){  
            System.out.println("unknown host!");  
        }  
        return null;  
  
    }  
  
    public static String getHostIp(InetAddress netAddress){  
        if(null == netAddress){  
            return null;  
        }  
        String ip = netAddress.getHostAddress(); //get the ip address  
        return ip;  
    }  
    public static String getHostName(String  ip){ 
    	String[] addrs=ip.split("[.]{1}");
    	ByteArrayOutputStream oo=new ByteArrayOutputStream();
    	oo.toByteArray();
    	Arrays.stream(addrs).forEach(s->{
    		//System.out.println(s);
    		oo.write(Integer.valueOf(NumUtils.fromUnsignedInt(Integer.valueOf(s))));
    		});
    	byte[] dd=oo.toByteArray();
    	System.out.println(">>>>>>"+(byte)172);
    	System.out.println(">>>>>>"+(172^256));
    	System.out.println(new Byte("127"));
    	InetAddress netAddress=null;
    
		try {
			netAddress = InetAddress.getByAddress(dd);
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        String name = netAddress.getHostName(); //get the host address  
        return name;  
    }
    
    public static String getHostName(InetAddress netAddress){  
        if(null == netAddress){  
            return null;  
        }  
        String name = netAddress.getHostName(); //get the host address  
        return name;  
    }  
    /**
     * 
     * @return
     */
    public static String getProjectPath(){
    	return System.getProperty("user.dir");
    }
  

	/**
	 * 获取系统编码
	 * @return
	 */
	public static String getEncoding(){
		//Charset.defaultCharset() 
		return System.getProperty("file.encoding"); 
	}
	
}
